package cn.liulin.llcommon.pojo.response;

/**
 * 响应实体（json）
 *
 * @author gjw
 * @date 2019年8月6日
 */
public class ResObj {

    /**
     * 应答前台是否成功（true:成功;false:失败）
     */
    private Boolean success;
    /**
     * 返回给前台所需对象
     */
    private Object data;
    /**
     * 返回给前台的简单描述（或提示语）
     */
    private String msg;

    /**
     * 返回代码值
     */
    private Integer code;

    public ResObj() {
    }

    public ResObj(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public ResObj(boolean success, String msg, int code) {
        this.success = success;
        this.msg = msg;
        this.code = code;
    }

    public ResObj(boolean success, String msg, int code, Object data) {
        this.success = success;
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public ResObj(boolean success, Object data, int code) {
        this.success = success;
        this.code = code;
        this.data = data;
    }

    public ResObj(Object data, boolean success) {
        this.success = success;
        this.data = data;
    }

    public ResObj(boolean success) {
        this.success = success;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 操作失败
     *
     * @param msg 提示信息
     * @return
     */
    public static ResObj error(String msg) {
        ResObj obj = new ResObj(false, msg);
        return obj;
    }

    public static ResObj error(Integer code, String msg, Object data) {
        return new ResObj(false, msg, code, data);
    }

    public static ResObj error(String msg, Integer code) {
        ResObj obj = new ResObj(false, msg);
        obj.setCode(code);
        obj.setMsg(msg);
        return obj;
    }

    public static ResObj ok(String msg, Integer code) {
        ResObj obj = new ResObj(true);
        obj.setCode(code);
        obj.setMsg(msg);
        return obj;
    }

    public static ResObj ok(Object data) {
        ResObj obj = new ResObj(true);
        obj.setCode(200);
        obj.setData(data);
        return obj;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
